/**
  ******************************************************************************
  * @file    Pid.h
  * @author  STMicroelectronics
  * @date    31-May-2022
  * @brief   This file contains the headers of the Pid Module.
  ******************************************************************************
  *
  * @copyright (c) 2018(-2024) STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file in
  * the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PID_H
#define __PID_H


/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include "dpwr_cntrl.h"
#ifdef STM32F334x8
  #include "stm32f3xx_hal.h" 
#elif defined STM32G474xx
  #include "stm32g4xx_hal.h" 
#else
  #error CPU  not specified
#endif


/* Exported types ------------------------------------------------------------*/
/**
  * @brief  Proportional integral compensator data structure
  * @details Data structure containing all parameters of a proportional integral compensator in both float and signed int type
  */
typedef struct {
  float Ref;
  float Feed;
  float Kp; 
  float Ki;
  float Ts;
  float Integral;
  float PIout;
  float PIout_sat;
  float PIsat_up;
  float PIsat_down;
  float error;
  float Integralout;
  FlagStatus resetPI;  
  float k0;
  float k1;
  float Antiwindup_Term;
  FlagStatus satPI_toggle;
  FlagStatus antiwindPI_toggle;
  float Antiwindup_Gain;
  float resetValue;

  uint8_t PI_Q_FxP;
  int32_t Ref_s32;  
  int32_t Feed_s32;   
  int32_t Integral_s32;
  int32_t PIout_s32;
  int32_t PIout_sat_s32;
  int32_t PIsat_up_s32;
  int32_t PIsat_down_s32;  
  int32_t error_s32;
  int32_t Integralout_s32;  
  uint32_t k0_s32;  
  uint32_t k1_s32;
  int32_t Antiwindup_Term_s32;
  int32_t Antiwindup_Gain_s32;
  int32_t resetValue_s32;
  
}DPC_PI_t;

/**
  * @brief  Proportional integral derivative compensator data structure
  * @details Data structure containing all parameters of a proportional integral derivative compensator float type
  */
typedef struct CNTRL_PID
{
    float   m_Ref;
    float   m_Fdbk;
    float   m_Kp;
    float   m_Ki;
    float   m_Kd;
    float   m_Integral;
    float   m_Error;
    float   m_Out;
    float   m_Min;
    float   m_Max;
} CNTRL_PID_DataFloat;


/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void DPC_PI_Init(DPC_PI_t *pPI,float Init_Val_Kp,float Init_Val_Ki,float Init_Val_Ts,float Init_PIsat_up, float Init_PIsat_down,FlagStatus satPI_toggle_local,FlagStatus antiwindPI_toggle_local,float Antiwindup_Gain_local,float resetValue);
float DPC_PI(float Ref, float Feed , DPC_PI_t *pPI);
int32_t DPC_PI_s32(int32_t Ref_s32, int32_t Feed_s32 , DPC_PI_t *pPI);
void PI_RESET(DPC_PI_t *pPI);
//void CNTRL_pid( CNTRL_3p3zDataFloat* Ptr );
void CNTRL_PI_Regulator( CNTRL_PID_DataFloat* Ptr );

 
#endif
